//
//  RequestData.m
//  天气预报
//
//  Created by inphase on 17/8/18.
//  Copyright © 2017年 inphase. All rights reserved.
//

#import "RequestDataLzj.h"
#import <AFNetworking.h>

#import "LzjModel.h"
#import "WeekModel.h"

@interface RequestDataLzj ()
@property(nonatomic,copy)blockA blArray;
@property(nonatomic,strong)NSMutableArray*dataArray;
@end

@implementation RequestDataLzj



#pragma mark-懒加载
-(NSMutableArray *)dataArray{
    if (_dataArray==nil) {
        _dataArray=[[NSMutableArray alloc]init];
    }
    return _dataArray;
}

+(void)requestDate:(NSString*)cityName andBlock:(blockA)blArrar{
    
    NSString *utf8 = [cityName stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSString*url=[NSString stringWithFormat:@"http://api.avatardata.cn/Weather/Query?key=d349c4a4ed8f46c5809502035566eb6c&cityname=%@",utf8];
       
    [manager GET:url parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    }
         success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
             
//    
             LzjModel*lzj=[[LzjModel alloc]initWithDic:responseObject];
             
            NSArray*wether=  responseObject[@"result"][@"weather"];
             NSMutableArray*arryData=@[].mutableCopy;
             for (NSDictionary*dict in wether) {
                 
                 WeekModel*week=[WeekModel new];
                NSLog(@"%@",dict[@"info"][@"day"]);
                NSArray*arr=dict[@"info"][@"day"];
                 week.terper=arr[2];
                 week.info=arr[1];
                 week.direct=arr[3];
                 
                 [arryData addObject:week];
             }
             
             
             blArrar(lzj,arryData);
             
             NSLog(@"%@",responseObject);
             
             NSLog(@"这里打印请求成功要做的事");
             
         }
         failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull   error) {
             
             NSLog(@"%@",error);  //这里打印错误信息
             
         }];
    
}



@end
